package com.coffee.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.coffee.admin.api.common.query.GtRegionQuery;
import com.coffee.admin.api.common.result.GtRegionResult;
import com.coffee.admin.api.common.service.GtRegionService;
import com.coffee.core.anotation.OperLog;
import com.coffee.core.result.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping
@RestController
public class GtRegionController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(GtRegionController.class);

    @DubboReference
    private GtRegionService gtRegionService;

    @RequestMapping(value = "/all/address", method = {RequestMethod.POST})
    public Result<List<GtRegionResult>> address(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        String isMustCity = jsonObject.getString("isMustCity");
        Result<List<GtRegionResult>> result = Result.success(null);
        if ("Y".equals(isMustCity)){
            GtRegionQuery param=new GtRegionQuery();
            param.setIsMustCity(isMustCity);
            List<GtRegionResult> list = gtRegionService.getList(param);
            result.setData(list);
        }else {
            List<GtRegionResult> list = gtRegionService.getList();
            result.setData(list);
        }

        return result;
    }
}
